chrome.contextMenus.create({
	title: "Envoyer vers Smart Kiwi",
	contexts:["selection"], 
	onclick: function(info, tab){ 
		var datas = info.selectionText;
		alert(info.selectionText);
		chrome.storage.sync.get({
			port: 8080
		}, function(items) {
			alert(items.port);
			var ws = new WebSocket ("ws://localhost:"+items.port);
			alert("WS CREATED");
			ws.onopen = function () {
				alert("WS OPEN");
				ws.send("SENDTEXT \""+datas+"\"");
				alert("SENT");
			};
			
		});
		
	}
});

chrome.contextMenus.create({
	title: "Envoyer vers Smart Kiwi en indiquant une fiche",
	contexts:["selection"], 
	onclick: function(info, tab){ 
		var datas = info.selectionText;
		alert(info.selectionText);
		chrome.storage.sync.get({
			port: 8080
		}, function(items) {
			alert(items.port);
			var ws = new WebSocket ("ws://localhost:"+items.port);
			alert("WS CREATED");
			ws.onopen = function () {
				alert("WS OPEN");
				ws.send("SENDTEXT \""+datas+"\" true");
				alert("SENT");
			};
			
		});
		
	}
});

